package com.example.administrator.foodrowfresh.jiao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.superBase.MyBaseAdapter;

import org.xutils.x;

import java.util.List;
import java.util.Map;

/**
 * Created by Bob on 2016/4/20.
 */
public class PromotionItemGVAdapter extends MyBaseAdapter<Map<String, String>> {

    //监听点击的id
    private int DETAIL_ID;

    private Context mContext;
    private List<Map<String, String>> mDatas;
    private LayoutInflater inflater;

    public PromotionItemGVAdapter(List<Map<String, String>> datas, Context context) {
        super(datas, context);
        mContext = context;
        mDatas = datas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler;
        if (convertView == null) {
            convertView = inflater.from(mContext).inflate(R.layout.promotion_activity_list_gridview, parent, false);
            hodler = new ViewHodler(convertView);
            hodler.image = (ImageView) convertView.findViewById(R.id.promotion_activity_item_iv);
            hodler.name = (TextView) convertView.findViewById(R.id.promotion_activity_item_name);
            hodler.now_price = (TextView) convertView.findViewById(R.id.promotion_activity_item_tv_now_price);
            hodler.weight = (TextView) convertView.findViewById(R.id.promotion_activity_item_tv_weight);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        hodler.name.setText(mDatas.get(position).get("name"));
        hodler.now_price.setText(mDatas.get(position).get("now_price"));
        hodler.weight.setText(mDatas.get(position).get("weight"));

        String image = mDatas.get(position).get("image");
        x.image().bind(hodler.image, image);
        return convertView;
    }



    public class ViewHodler {
        TextView name, now_price, weight;
        ImageView image;
        private ViewHodler(View v){

        }

    }
}
